#全局变量
#  num = 10
from itertools import filterfalse


def is_prime(n):
#局部变量    num=10
    if n <2:
        return False
    for i in range(2,int(n ** 0.5 ) +1):
        if n%i==0:
            return False
    return True
print(is_prime(30))

#递归求阶乘
def factorial(n):
    if n==1:
        return 1
    else:
        return n*factorial(n-1)
print(factorial(5))
#打印边长为2个星号的正方形
for i in range(2):
    for j in range(2):
        print("*",end="\t")
    print()

def print_triangle(length):
    for i in range(length):
        for j in range (length):
            print("*",end="\t")
        print()

print_triangle(2)
print_triangle(3)
print_triangle(4)

#传参
def connect(ip,port):
    print(f"设备{ip}:{port}连接！")
connect(ip="127.0.0.1",port=8080)
#部分参数只接收采用位置传递方式的实参
def func(a,b,/,c):
    print(a,b,c)
func(1,2,3)
func(1,2,c=3)
#参数的打包与解包
def test(a,b,c,d,e):
    print(a,b,c,d,e)
nums=(11,22,33,44,55)
num ={"a":11,"b":22,"c":33,"d":44,"e":55}
test(*nums)
test(**num)

def test(a,b,c,d,e):
    print(a,b,c,d,e)
    return a+b+c+d+e
nums=[11,22,33,44,55]
print(test(*nums))
#混合传递
def test(a,b,c=33,*args,**kwargs):
    print(a,b,c,args,kwargs)
test(1,2)
test(1,2,3)
test(1,2,3,4)
test(1,2,3,4,e=5)


#兔子数列
def f(n):
    if n==0:
        return  1
    elif n==1:
        return 1
    else:
        return f(n-1)+f(n-2)
print(f(3))

